<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>添加分类</title>
    <link rel="stylesheet" href="__ADMIN__/pear/css/pear.css" />
    <style>
        .pear-container {
            background-color: white;
        }
        
        body {
            margin: 10px;
        }
    </style>
</head>

<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label for="" class="layui-form-label">父级</label>
            <div class="layui-input-block">
                <select name="fid" lay-verify="requried">
                    <option value="0">顶级</option>
                    {foreach $category as $k1=>$p1}
                        <option value="{$p1.id}">{$p1.name}</option>
                        {if isset($p1['children']) && !empty($p1['children']) }
                            {foreach $p1['children'] as $k2=>$p2}
                                <option value="{$p2.id}" >&nbsp;&nbsp;&nbsp;┗━━{$p2.name}</option>
                            {/foreach}
                        {/if}
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="" class="layui-form-label">分类名称：</label>
            <div class="layui-input-block">
                <input type="text" maxlength="16" name="name" lay-verify="required" placeholder="请输入分类名称，必填" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">seo标题：</label>
            <div class="layui-input-block">
                <input type="text" maxlength="30" name="seo_title" placeholder="请输入seo标题，可空" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">seo描述：</label>
            <div class="layui-input-block">
                <textarea name="seo_desc" placeholder="请输入seo描述，可空" class="layui-textarea"></textarea>

            </div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">seo别名：</label>
            <div class="layui-input-block">
                <input type="text" maxlength="16" name="seo_alias" placeholder="用于url上，可空" class="layui-input">
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
    </form>
    <script src="__ADMIN__/layui/layui.js"></script>
    <script src="__ADMIN__/pear/pear.js"></script>
    <script>
        layui.use(['form', 'element', 'jquery'], function() {
            var form = layui.form;
            var element = layui.element;
            var $ = layui.jquery;

            form.on('submit(save)', function(data) {
                $.ajax({
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function(res) {
                        //判断有没有权限
                        if (res && res.code == 999) {
                            layer.msg(res.msg, {
                                icon: 5,
                                time: 2000,
                            })
                            return false;
                        } else if (res.code == 0) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000
                            }, function() {
                                parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                                window.parent.location.reload();
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
                return false;
            });
        });
    </script>
</body>

</html>